package com.estar.integaration.Util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Author: YJL
 * Date: 2021/11/21 11:15
 **/
public class StringUtil {


  public static String toUtf8String(String strInput){
    StringBuffer output = new StringBuffer();
    for (int i = 0; i < strInput.length(); i++)
    {
      output.append("\\u" +Integer.toString(strInput.charAt(i), 16));
    }
    return output.toString();
  }

  //补齐位数
  public static String autoGenericCode(String code,int num){
      int size = code.length();
      int x = num - size;
      for(int i = 0 ; i < x; i++){
        code =  " " + code ;
      }
      return code;

  }



  public static String[] splitStrByChar(String str,String c){
    return str.split(c);
  }

  public static String replaceSpace(String s) {
    Pattern p = Pattern.compile("\\s*|\t|\r|\n");
    Matcher m = p.matcher(s);
    s = m.replaceAll("");
    System.out.println(s);
    return s;
  }


  //@ author: walker
  //用正则表达式判断字符串是否为数字（含负数）
  public static boolean isNumeric(String str) {
    String regEx = "^-?[0-9]+$";
    Pattern pat = Pattern.compile(regEx);
    Matcher mat = pat.matcher(str);
    if (mat.find()) {
      return true;
    }
    else {
      return false;
    }
  }

}
